package com.aididi.interfaces.impl;

import com.aididi.entity.Book;
import com.aididi.interfaces.BookRepository;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;

/**
 * @Auther: zx.xu
 * @Description:
 */
@Component
public class BookRepositoryImpl implements BookRepository {

    @Override
    @Cacheable("books")
    public Book getByIsbn(String isbn) {
        simulateSlowService();
        return new Book(isbn,"hi");
    }


    private void simulateSlowService(){
        /**
         * 休眠3秒
         */
        try {
            long time = 3000L;
            Thread.sleep(time);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
